<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="标段编号" prop="blockNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.blockNumber" placeholder="请填写标段编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="标段名称" prop="noName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.noName" placeholder="请填写标段名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="中标状态" prop="winningState"
                :rules="[
                 ]">
                <el-select v-model="inputForm.winningState" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('winning_state')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报价方式" prop="priceTerms"
                :rules="[
                 ]">
              <el-input v-model="inputForm.priceTerms" placeholder="请填写报价方式"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="总报价" prop="totalOffer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalOffer" placeholder="请填写总报价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="折扣报价" prop="discountOffer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.discountOffer" placeholder="请填写折扣报价"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预估中标金额" prop="estimateBidAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.estimateBidAmount" placeholder="请填写预估中标金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="中标区域及份额" prop="bidAreaAndShare"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidAreaAndShare" placeholder="请填写中标区域及份额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="经营分类" prop="manageClassifyc"
                :rules="[
                 ]">
                <el-select v-model="inputForm.manageClassifyc" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('manage_classify')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="业务分类" prop="businessClassify"
                :rules="[
                 ]">
                <el-select v-model="inputForm.businessClassify" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('business_classify')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="中标日期" prop="bidDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.bidDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目取费标准" prop="projectFeeStandard"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectFeeStandard" placeholder="请填写项目取费标准"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="延续项目的上年度中标折扣" prop="continueProjectWinningDiscount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.continueProjectWinningDiscount" placeholder="请填写延续项目的上年度中标折扣"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="已有定额标准" prop="existNorm"
                :rules="[
                 ]">
              <el-input v-model="inputForm.existNorm" placeholder="请填写已有定额标准"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="中标金额" prop="bidPrice"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bidPrice" placeholder="请填写中标金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="投标信息id" prop="projectRegistration.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择投标信息id"
            labelName = 'tenderNumber'
            labelValue = 'id'
            :value = "inputForm.projectRegistration.id"
            :limit="1"
            @getValue='(value) => {inputForm.projectRegistration.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'tenderNumber',
              label: '投标编号'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'tenderNumber',
              label: '投标编号'
            }
            ]"
            dataListUrl="/epc/biddingprojectregistration/biddingProjectRegistration/list"
            entityBeanName="biddingProjectRegistration"
            queryEntityUrl="/epc/biddingprojectregistration/biddingProjectRegistration/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          blockNumber: '',
          noName: '',
          winningState: '',
          priceTerms: '',
          totalOffer: '',
          discountOffer: '',
          estimateBidAmount: '',
          bidAreaAndShare: '',
          manageClassifyc: '',
          businessClassify: '',
          bidDate: '',
          projectFeeStandard: '',
          continueProjectWinningDiscount: '',
          existNorm: '',
          bidPrice: '',
          projectRegistration: {
            id: ''
          },
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建投标标段`
        } else if (method === 'edit') {
          this.title = '修改投标标段'
        } else if (method === 'view') {
          this.title = '查看投标标段'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/tenderbid/tenderBid/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.tenderBid)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/tenderbid/tenderBid/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>